class coo:
    def __init__(self,x,y,z):
        self.x=x
        self.y=y
        self.z=z
    def __eq__(self,other):
        return self.z==other.z
    def __ne__(self,other):
        return not(self.z==other.z)
    def __gt__(self,other):
        return self.z>other.z
    def __lt__(self,other):
        return self.z<other.z
    def __ge__(self,other):
        return self.z>=other.z
    def __le__(self,other):
        return self.z<=other.z
    def __sub__(self,other):
        return ((self.x-other.x)**2+(self.y-other.y)**2+(self.z-other.z)**2)**0.5
n=int(input())
tlist=[]
for _ in range(n):
    temp=list(map(int,input().split()))
    tlist.append(coo(temp[0],temp[1],temp[2]))
tlist.sort()
tlist=[i-j for i,j in zip(tlist[0:-1],tlist[1:])]
print("%.3f"%sum(tlist))